package com.mercury.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class LogAdviceAnnotation {

	@Pointcut("execution(* com.mercury.beans.TimeBook.doAudit(..))")
	public void start(){}
	@Before("start() && args(name,..)")
	public void startBefore(String name){
		System.out.println(name + " starting...");
	}
	
	@Pointcut("execution(* com.mercury.beans.TimeBook.doBreak(..))")
	public void end(){}
	@AfterReturning("end() && args(name,..)")
	public void endAfter(String name){
		System.out.println(name + " ending...");
	}
	
	@Pointcut("execution(* com.mercury.beans.TimeBook.doCheck(..))")
	public void error(){}
	@AfterThrowing("error() && args(name,..)")
	public void errorThrow(String name){
		System.out.println(name + "has errors...");
	}
	
	@Pointcut("execution(* com.mercury.beans.TimeBook.doDelete(..))")
	public void delete(){}
	@After("delete()")
	public void deleteAfter(){
		System.out.println("deleting...");
	}
	
	@Pointcut("execution(* com.mercury.beans.TimeBook.doAudit(..))")
	public void around(){}
	@Around("around() && args(name,..)")
	public Object aroundService(ProceedingJoinPoint pjp, String name) throws Throwable{
		System.out.println(name + " around before...");
		Object obj = pjp.proceed();
		System.out.println(name + " around after...");
		return obj;
	}
}
